package com.yichat.micro.msghttpservice.core.okHttp;

import com.yichat.micro.msghttpservice.common.Constants;
import com.yichat.micro.msghttpservice.common.vo.MsgHttpRequestVo;
import com.yichat.micro.msghttpservice.core.retry.RetryMsgHttpRequestVo;
import okhttp3.Protocol;
import okhttp3.Request;
import okhttp3.Response;

/**
 * Created by chenmohan on 2019/04/19
 *
 * @description
 */
public class OkHttpResponseBuilder {

    public static Response callback(Request request, RetryMsgHttpRequestVo requestParam) {
        return new Response.Builder()
                .request(request)
                .protocol(Protocol.HTTP_1_1)
                .code(Constants.stauts_callback_success)
                .message(Constants.msg_stauts_callback_success)
                .header("id", String.valueOf(requestParam.getSid()))
                .header("callbacked", "1")
                .header("buz", requestParam.getVo().getBuz())
                .build();
    }

    public static Response asnycCommit(Request request, RetryMsgHttpRequestVo requestParam) {
        return new Response.Builder()
                .request(request)
                .protocol(Protocol.HTTP_1_1)
                .code(Constants.stauts_async)
                .message(Constants.msg_status_async)
                .header("id", String.valueOf(requestParam.getSid()))
                .header("sync", Constants.ok)
                .header("buz", requestParam.getVo().getBuz())
                .build();
    }

    public static Response timeout(RetryMsgHttpRequestVo retryMsgHttpRequestParam) {
        MsgHttpRequestVo requestParam = retryMsgHttpRequestParam.getVo();
        return new Response.Builder()
                .request(new Request.Builder().url(requestParam.getUrl()).build())
                .protocol(Protocol.HTTP_1_1)
                .code(Constants.status_timeout)
                .message(Constants.msg_status_timeout)
                //   .body(ResponseBody.create(MediaType.parse(requestParam.getMediaType()), Constants.msg_status_timeout))
                .header("id", String.valueOf(retryMsgHttpRequestParam.getSid()))
                .build();
    }
}
